<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .gray {
      color: gray;
    }

    .black {
      color: black;
    }
  </style>
</head>

<body>
  <input type="text" value="请输入要搜索的内容" class="gray" id="txt">
  <input type="button" value="搜索" id="btn" />

  <script src="js/common.js"></script>
  <script>
    var txt = my$("txt");
    var btn = my$("btn");

    // 获取焦点 onfocus
    // 如果是默认的，需要清空文字，文字颜色为黑色
    addEvent(txt, "focus", function () {
      if (this.value === "请输入要搜索的内容") {
        this.value = "";
        this.className = "black";
      } else {
        this.value = "请输入要搜索的内容";
        this.className = "gray";
      }
    })
    // 失去焦点 onblur
    // 如果内容为空，需要恢复默认值，文字颜色为灰色
    // 不为空，不用修改
    addEvent(txt, "blur", function () {
      if (this.value === "" || this.value === "请输入要搜索的内容") {
        this.value = "请输入要搜索的内容";
        this.className = "gray";
      }
    })
  </script>
</body>

</html>